<include file="public@header">
<body>
    <style>
        html{
            overflow: hidden;
        }
        .agojilu{
            display: block;
            width: 0.22rem;
            height: 0.26rem;
            position: absolute;
            top: 0.29rem;
            right: 0.3rem;
            z-index: 1000;
        }
        .agojilu>img{
            width: 100%;
        }
    </style>
    <a href="{:url('user/zichan/record',array('act'=>'1'))}" class="agojilu"><img src="__STATIC__/hybit/images/jilu.png" alt="" /></a>
    <div class="bgbg headhead">
        <h3 class="mytitle">{:lang('Charge')}</h3>
        <div class="cb">
           <div class="zz_cb">
            <div class="choosebdiv"> 
            <foreach name="address_list" item="vo">
                <p class="chooseb <if $key == 0>active</if>" data-address="{$vo.address}">{$vo.alias}</p>
            </foreach>
            </div>
            <div id="qrcode" class="cbewm">
                
            </div>
            <div id="qrcode1" class="cbewm" style="width:360px;height:360px;position:absolute;top:10000px;">
                
            </div>
            <button type="button" class="bcewmbtn" onclick="sctp()">{:lang('Save QR Code')}</button>
            <div class="cbaddress">
                <h3>{:lang('Address')}</h3>
                <p id="address"></p>
                <button type="button" onclick="CopyAddress()">{:lang('Copy Address')}</button>
            </div>
            <div class="cbnote">
                <h3>{:lang('Prompt')}</h3>
                
            <if cookie('think_var') == 'en-us'>
                <p>
                    You need to confirm the entire network node to get the account.Any non USDT recharge the assets to USDT cannot be retrieved after the address!<br>
                    Minimum credit amount:1 USDT,less than 1 USDT will not be able to arrive and cannot be returned.<br>
                </p>
            <else/>
                <p>
                    请勿向上述地址充值任何非USDT资产，否则资产将不可找回。<br>
                    您充值至上述地址后，需要整个网络节点确认，12次网络确认后到账，12次网络确认后可提币。<br>
                    最小充值金额：1USDT，小于最小金额的充值将不会上账且无法退回。<br>
                </p>
            </if>

                
              </div>  
            </div>
        </div>
        <input type="text" readonly value="" id="url" style="position:absolute;left:-9999px;opacity:0;">
    </div>
    <script src="__STATIC__/hybit/js/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
    <script src="__STATIC__/hybit/js/html2canvas.js"></script>
    <script type="text/javascript">

    
    $('.chooseb').click(function(event) {
        $('#qrcode1').html(' ')
        // qrcode.clear()
        let $this = $(this)
        let address = $this.attr('data-address')
        $this.siblings().removeClass('active')
        $this.addClass('active')
        $('#url').val(address)
        $('#address').html(address)
        $('#qrcode1').qrcode({width: 360,height: 360,text: address});
        console.log($('#qrcode1').html())
        new html2canvas(document.getElementById('qrcode1'),{useCORS: true }).then(canvas => {
            // canvas为转换后的Canvas对象
            let oImg1 = new Image();
            oImg1.src = canvas.toDataURL("image/png");
            //console.log(oImg1.src)
            $('#qrcode').html('<img src="'+oImg1.src+'" style="width:2.24rem;height:2.24rem;">');
        });
    });


    let address = $('.choosebdiv p:eq(0)').attr('data-address');
    $('#url').val(address)
    $('#address').html(address)
    $('#qrcode1').qrcode({width: 360,height: 360,text: address});
    new html2canvas(document.getElementById('qrcode1'),{useCORS: true }).then(canvas => {

        let oImg = new Image();
        oImg.src = canvas.toDataURL("image/png");
        $('#qrcode').html('<img src="'+oImg.src+'" style="width:2.24rem;height:2.24rem;">');
    });

    var savaFile=function(data,filename)
        {
            var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
            save_link.href = data;
            save_link.download = filename;
            var event=document.createEvent('MouseEvents');
            event.initMouseEvent('click',true,false,window,0,0,0,0,0,false,false,false,false,0,null);
            save_link.dispatchEvent(event);
        };


    function sctp(){
        new html2canvas(document.getElementById('qrcode'),{useCORS: true }).then(canvas => {
            // canvas为转换后的Canvas对象
            let oImg = new Image();
            oImg.src = canvas.toDataURL("image/png");  // 导出图片
            //document.body.appendChild(oImg);  // 将生成的图片添加到body
            console.log(oImg)
            let time1 = new Date().getTime()
            savaFile(oImg.src,time1)
        });
    }

    function CopyAddress() {
        let url = $('#url')[0];
        console.log(url)
        url.select();
        document.execCommand("Copy");
        alert('{:lang("Copy successfully")}');
    }
    </script>
</body>
</html>